﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QqForm
{
    public class MessageDealGetQqList : MessageDealBase
    {
        public override object ShowMessage(TcpClass tcpClass, byte[] msg)
        {
            int y = 0;
            string cmdQq = Encoding.UTF8.GetString(msg, 0, msg.Length);
            if (cmdQq.IndexOf("VER", StringComparison.Ordinal) == -1)
            {
                return null;
            }
            string[] resultArrary = cmdQq.Split('&');
            List<string> listResult = new List<string>(resultArrary);
            string np = resultArrary[5].Split('=')[1];
            if (np != "65535")
            {
                new QqCommand().GetQqListSendCommand(tcpClass, np);
            }
            else
            {
                y = 1;
            }
            if (y == 1)
            {
                new QqCommand().GetQqListIsOnlineCommand(tcpClass, "0");
                y = 0;
            }
            QQListHelper(resultArrary[7], resultArrary[9]);
            return null;
        }

        private void QQListHelper(string uid, string nk)
        {
            string[] uids = uid.Split('=')[1].Split(',');
            string[] nks = nk.Split('=')[1].Split(',');
            for (int i = 0; i < uids.Length - 1; i++)
            {
                QqListHelper.QqLists.Add(new QqList(uids[i], nks[i]));
            }
        }
    }
}
